package cn.hchaojie.camp.day08;

import org.junit.Test;

import cn.hchaojie.camp.week1.qa.Student;

public class DemoStringFormat {
	@Test
	public void test() {
		//  年纪为xx的学生xx正在一脸懵逼的听着xxx的课程, 他考了xx分
		
		Student student = new Student("王小虎", 18, "面向对象");
		student.setScore(88.5);
		System.out.println("年纪为" + student.getAge() 
			+ "的学生" + student.getName() + "正在听着" + student.getContent() + "的课程");
		
//		StringBuilder sb = new StringBuilder();
//		sb.append("年纪为");
//		sb.append(student.getAge());
		
		String format = "年纪为%d的学生%s正在一脸懵逼的听着%s的课程，他考了%.1f分";
		System.out.println(String.format(format, 
				student.getAge(), student.getName(), student.getContent(), student.getScore()));
		
		// String.format 和 printf效果是一样的
		System.out.printf(format, 
				student.getAge(), student.getName(), student.getContent(), student.getScore());
	}
}
